<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>多回路选型工具</title>
    <style>
        body {
            font-family: sans-serif;
            padding: 20px;
            background-color: #f4f4f4;
        }
        .container {
            max-width: 900px;
            margin: auto;
            background: #fff;
            border: 1px solid #ccc;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0,0,0,0.1);
        }
        h1 {
            text-align: center;
            color: #333;
        }
        .circuit-card {
            border: 1px solid #ddd;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 15px;
            background-color: #fafafa;
            position: relative;
        }
        .circuit-card h3 {
            margin-top: 0;
            margin-bottom: 15px;
            color: #555;
        }
        .form-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
            gap: 15px;
        }
        .form-group {
            display: flex;
            flex-direction: column;
        }
        label {
            margin-bottom: 5px;
            font-weight: bold;
            color: #555;
        }
        select {
            width: 100%;
            padding: 10px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .remove-btn {
            position: absolute;
            top: 10px;
            right: 10px;
            background: #ff4d4d;
            color: white;
            border: none;
            border-radius: 50%;
            width: 24px;
            height: 24px;
            cursor: pointer;
            font-weight: bold;
            line-height: 24px;
            text-align: center;
        }
        #add-circuit-btn {
            width: 100%;
            padding: 12px 15px;
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            margin-bottom: 20px;
        }
        #add-circuit-btn:hover {
            background-color: #218838;
        }
        #add-circuit-btn:disabled {
            background-color: #aaa;
            cursor: not-allowed;
        }
        #result-container {
            margin-top: 20px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 8px;
            background-color: #f9f9f9;
            min-height: 50px;
            overflow-x: auto;
        }
        #result-container h2 {
            margin-top: 0;
            color: #007bff;
            text-align: center;
            margin-bottom: 20px;
        }
        .result-table {
            width: 100%;
            border-collapse: collapse;
        }
        .result-table th, .result-table td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: left;
            white-space: nowrap;
        }
        .result-table th {
            background-color: #f2f2f2;
        }
        .placeholder-text {
            color: #999;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>多回路选型工具</h1>
        <div id="circuits-container"></div>
        <button id="add-circuit-btn">添加回路</button>
        <div id="result-container">
            <p class="placeholder-text">请添加并配置回路以查看结果</p>
        </div>
    </div>

    <template id="circuit-template">
        <div class="circuit-card">
            <h3 class="circuit-title">回路</h3>
            <button class="remove-btn" title="移除回路">×</button>
            <div class="form-grid">
                <div class="form-group">
                    <label>电压</label>
                    <select class="voltage">
                        <option value="D380">D380, 380V</option>
                        <option value="D220">D220, 220V</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>控制方式</label>
                    <select class="control-method">
                        <option value="BP">BP-变频</option>
                        <option value="D">D-工频</option>
                        <option value="C">C/工变</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>电机功率 (kW)</label>
                    <select class="motor-power">
                        <option value="0.75">0.75</option>
                        <option value="1.1">1.1</option>
                        <option value="1.5">1.5</option>
                        <option value="2.2">2.2</option>
                        <option value="3">3</option>
                        <option value="4">4</option>
                        <option value="5.5">5.5</option>
                        <option value="7.5">7.5</option>
                        <option value="11">11</option>
                        <option value="15">15</option>
                        <option value="18.5">18.5</option>
                        <option value="22">22</option>
                        <option value="30">30</option>
                        <option value="37">37</option>
                        <option value="45">45</option>
                        <option value="55">55</option>
                        <option value="75">75</option>
                        <option value="90">90</option>
                        <option value="110">110</option>
                        <option value="132">132</option>
                        <option value="160">160</option>
                        <option value="185">185</option>
                        <option value="200">200</option>
                        <option value="220">220</option>
                        <option value="250">250</option>
                        <option value="280">280</option>
                    </select>
                </div>
            </div>
        </div>
    </template>

    <script>
        // Assuming D->K (工频->基本型), BP->S (变频->智能型), C->P (工变->PLC)
        const selectionData = {
            "D380": {
                "D": [
                    { power: 0.75, model: 'XJ01-0.75K', plastic_case: 'DZ47-3P-2A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/1.6A' },
                    { power: 1.1, model: 'XJ01-1.1K', plastic_case: 'DZ47-3P-4A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/2.5A' },
                    { power: 1.5, model: 'XJ01-1.5K', plastic_case: 'DZ47-3P-4A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/4A' },
                    { power: 2.2, model: 'XJ01-2.2K', plastic_case: 'DZ47-3P-6A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/6A' },
                    { power: 3, model: 'XJ01-3K', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/8A' },
                    { power: 4, model: 'XJ01-4K', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-1210', thermal_relay: 'JR36-20/10A' },
                    { power: 5.5, model: 'XJ01-5.5K', plastic_case: 'DZ47-3P-16A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/13A' },
                    { power: 7.5, model: 'XJ01-7.5K', plastic_case: 'DZ47-3P-20A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/18A' },
                    { power: 11, model: 'XJ01-11K', plastic_case: 'DZ47-3P-32A', contactor: 'CJX2-2510', thermal_relay: 'JR36-20/25A' },
                    { power: 15, model: 'XJ01-15K', plastic_case: 'DZ47-3P-40A', contactor: 'CJX2-3210', thermal_relay: 'JR36-20/32A' },
                    { power: 18.5, model: 'XJ01-18.5K', plastic_case: 'DZ47-3P-50A', contactor: 'CJX2-4011', thermal_relay: 'JR36-63/40A' },
                    { power: 22, model: 'XJ01-22K', plastic_case: 'DZ47-3P-63A', contactor: 'CJX2-5011', thermal_relay: 'JR36-63/50A' },
                    { power: 30, model: 'XJ01-30K', plastic_case: 'CM1-100/3p-80A', contactor: 'CJX2-6511', thermal_relay: 'JR36-63/63A' },
                    { power: 37, model: 'XJ01-37K', plastic_case: 'CM1-100/3p-100A', contactor: 'CJX2-8011', thermal_relay: 'JR36-160/80A' },
                    { power: 45, model: 'XJ01-45K', plastic_case: 'CM1-225/3p-125A', contactor: 'CJX2-9511', thermal_relay: 'JR36-160/100A' },
                    { power: 55, model: 'XJ01-55K', plastic_case: 'CM1-225/3p-160A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/120A' },
                    { power: 75, model: 'XJ01-75K', plastic_case: 'CM1-225/3p-200A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/160A' },
                    { power: 90, model: 'XJ01-90K', plastic_case: 'CM1-225/3p-225A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/200A' },
                ],
                "BP": [
                    { power: 0.75, model: 'XJ01-0.75S', plastic_case: 'DZ47-3P-2A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/1.6A' },
                    { power: 1.1, model: 'XJ01-1.1S', plastic_case: 'DZ47-3P-4A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/2.5A' },
                    { power: 1.5, model: 'XJ01-1.5S', plastic_case: 'DZ47-3P-4A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/4A' },
                    { power: 2.2, model: 'XJ01-2.2S', plastic_case: 'DZ47-3P-6A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/6A' },
                    { power: 3, model: 'XJ01-3S', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/8A' },
                    { power: 4, model: 'XJ01-4S', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-1210', thermal_relay: 'JR36-20/10A' },
                    { power: 5.5, model: 'XJ01-5.5S', plastic_case: 'DZ47-3P-16A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/13A' },
                    { power: 7.5, model: 'XJ01-7.5S', plastic_case: 'DZ47-3P-20A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/18A' },
                    { power: 11, model: 'XJ01-11S', plastic_case: 'DZ47-3P-32A', contactor: 'CJX2-2510', thermal_relay: 'JR36-20/25A' },
                    { power: 15, model: 'XJ01-15S', plastic_case: 'DZ47-3P-40A', contactor: 'CJX2-3210', thermal_relay: 'JR36-20/32A' },
                    { power: 18.5, model: 'XJ01-18.5S', plastic_case: 'DZ47-3P-50A', contactor: 'CJX2-4011', thermal_relay: 'JR36-63/40A' },
                    { power: 22, model: 'XJ01-22S', plastic_case: 'DZ47-3P-63A', contactor: 'CJX2-5011', thermal_relay: 'JR36-63/50A' },
                    { power: 30, model: 'XJ01-30S', plastic_case: 'CM1-100/3p-80A', contactor: 'CJX2-6511', thermal_relay: 'JR36-63/63A' },
                    { power: 37, model: 'XJ01-37S', plastic_case: 'CM1-100/3p-100A', contactor: 'CJX2-8011', thermal_relay: 'JR36-160/80A' },
                    { power: 45, model: 'XJ01-45S', plastic_case: 'CM1-225/3p-125A', contactor: 'CJX2-9511', thermal_relay: 'JR36-160/100A' },
                    { power: 55, model: 'XJ01-55S', plastic_case: 'CM1-225/3p-160A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/120A' },
                    { power: 75, model: 'XJ01-75S', plastic_case: 'CM1-225/3p-200A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/160A' },
                    { power: 90, model: 'XJ01-90S', plastic_case: 'CM1-225/3p-225A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/200A' },
                    { power: 110, model: 'XJ01-110S', plastic_case: 'CM1-400/3p-250A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/250A' },
                    { power: 132, model: 'XJ01-132S', plastic_case: 'CM1-400/3p-315A', contactor: 'CJ20-400', thermal_relay: 'JR36-400/315A' },
                    { power: 160, model: 'XJ01-160S', plastic_case: 'CM1-400/3p-400A', contactor: 'CJ20-400', thermal_relay: 'JR36-400/400A' },
                    { power: 185, model: 'XJ01-185S', plastic_case: 'CM1-630/3p-500A', contactor: 'CJ20-630', thermal_relay: 'JR36-630/500A' },
                    { power: 200, model: 'XJ01-200S', plastic_case: 'CM1-630/3p-500A', contactor: 'CJ20-630', thermal_relay: 'JR36-630/500A' },
                    { power: 220, model: 'XJ01-220S', plastic_case: 'CM1-630/3p-630A', contactor: 'CJ20-630', thermal_relay: 'JR36-630/630A' },
                    { power: 250, model: 'XJ01-250S', plastic_case: 'CM1-800/3p-800A', contactor: 'NSX-800', thermal_relay: 'JR36-630/630A' },
                    { power: 280, model: 'XJ01-280S', plastic_case: 'CM1-800/3p-800A', contactor: 'NSX-800', thermal_relay: 'JR36-630/630A' },
                ],
                "C": [
                    { power: 0.75, model: 'XJ01-0.75P', plastic_case: 'DZ47-3P-2A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/1.6A' },
                    { power: 1.1, model: 'XJ01-1.1P', plastic_case: 'DZ47-3P-4A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/2.5A' },
                    { power: 1.5, model: 'XJ01-1.5P', plastic_case: 'DZ47-3P-4A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/4A' },
                    { power: 2.2, model: 'XJ01-2.2P', plastic_case: 'DZ47-3P-6A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/6A' },
                    { power: 3, model: 'XJ01-3P', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/8A' },
                    { power: 4, model: 'XJ01-4P', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-1210', thermal_relay: 'JR36-20/10A' },
                    { power: 5.5, model: 'XJ01-5.5P', plastic_case: 'DZ47-3P-16A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/13A' },
                    { power: 7.5, model: 'XJ01-7.5P', plastic_case: 'DZ47-3P-20A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/18A' },
                    { power: 11, model: 'XJ01-11P', plastic_case: 'DZ47-3P-32A', contactor: 'CJX2-2510', thermal_relay: 'JR36-20/25A' },
                    { power: 15, model: 'XJ01-15P', plastic_case: 'DZ47-3P-40A', contactor: 'CJX2-3210', thermal_relay: 'JR36-20/32A' },
                    { power: 18.5, model: 'XJ01-18.5P', plastic_case: 'DZ47-3P-50A', contactor: 'CJX2-4011', thermal_relay: 'JR36-63/40A' },
                    { power: 22, model: 'XJ01-22P', plastic_case: 'DZ47-3P-63A', contactor: 'CJX2-5011', thermal_relay: 'JR36-63/50A' },
                    { power: 30, model: 'XJ01-30P', plastic_case: 'CM1-100/3p-80A', contactor: 'CJX2-6511', thermal_relay: 'JR36-63/63A' },
                    { power: 37, model: 'XJ01-37P', plastic_case: 'CM1-100/3p-100A', contactor: 'CJX2-8011', thermal_relay: 'JR36-160/80A' },
                    { power: 45, model: 'XJ01-45P', plastic_case: 'CM1-225/3p-125A', contactor: 'CJX2-9511', thermal_relay: 'JR36-160/100A' },
                    { power: 55, model: 'XJ01-55P', plastic_case: 'CM1-225/3p-160A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/120A' },
                    { power: 75, model: 'XJ01-75P', plastic_case: 'CM1-225/3p-200A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/160A' },
                    { power: 90, model: 'XJ01-90P', plastic_case: 'CM1-225/3p-225A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/200A' },
                    { power: 110, model: 'XJ01-110P', plastic_case: 'CM1-400/3p-250A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/250A' },
                    { power: 132, model: 'XJ01-132P', plastic_case: 'CM1-400/3p-315A', contactor: 'CJ20-400', thermal_relay: 'JR36-400/315A' },
                    { power: 160, model: 'XJ01-160P', plastic_case: 'CM1-400/3p-400A', contactor: 'CJ20-400', thermal_relay: 'JR36-400/400A' },
                    { power: 185, model: 'XJ01-185P', plastic_case: 'CM1-630/3p-500A', contactor: 'CJ20-630', thermal_relay: 'JR36-630/500A' },
                    { power: 200, model: 'XJ01-200P', plastic_case: 'CM1-630/3p-500A', contactor: 'CJ20-630', thermal_relay: 'JR36-630/500A' },
                    { power: 220, model: 'XJ01-220P', plastic_case: 'CM1-630/3p-630A', contactor: 'CJ20-630', thermal_relay: 'JR36-630/630A' },
                    { power: 250, model: 'XJ01-250P', plastic_case: 'CM1-800/3p-800A', contactor: 'NSX-800', thermal_relay: 'JR36-630/630A' },
                    { power: 280, model: 'XJ01-280P', plastic_case: 'CM1-800/3p-800A', contactor: 'NSX-800', thermal_relay: 'JR36-630/630A' },
                ]
            },
            "D220": {
                "D": [
                    { power: 0.75, model: 'XJ01-0.75K/D220', plastic_case: 'DZ47-3P-6A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/4A' },
                    { power: 1.1, model: 'XJ01-1.1K/D220', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/6A' },
                    { power: 1.5, model: 'XJ01-1.5K/D220', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-1210', thermal_relay: 'JR36-20/8A' },
                    { power: 2.2, model: 'XJ01-2.2K/D220', plastic_case: 'DZ47-3P-16A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/13A' },
                    { power: 3, model: 'XJ01-3K/D220', plastic_case: 'DZ47-3P-20A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/18A' },
                    { power: 4, model: 'XJ01-4K/D220', plastic_case: 'DZ47-3P-32A', contactor: 'CJX2-2510', thermal_relay: 'JR36-20/25A' },
                    { power: 5.5, model: 'XJ01-5.5K/D220', plastic_case: 'DZ47-3P-40A', contactor: 'CJX2-3210', thermal_relay: 'JR36-20/32A' },
                    { power: 7.5, model: 'XJ01-7.5K/D220', plastic_case: 'DZ47-3P-50A', contactor: 'CJX2-4011', thermal_relay: 'JR36-63/40A' },
                    { power: 11, model: 'XJ01-11K/D220', plastic_case: 'CM1-100/3p-80A', contactor: 'CJX2-6511', thermal_relay: 'JR36-63/63A' },
                    { power: 15, model: 'XJ01-15K/D220', plastic_case: 'CM1-100/3p-100A', contactor: 'CJX2-8011', thermal_relay: 'JR36-160/80A' },
                    { power: 18.5, model: 'XJ01-18.5K/D220', plastic_case: 'CM1-225/3p-125A', contactor: 'CJX2-9511', thermal_relay: 'JR36-160/100A' },
                    { power: 22, model: 'XJ01-22K/D220', plastic_case: 'CM1-225/3p-160A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/120A' },
                    { power: 30, model: 'XJ01-30K/D220', plastic_case: 'CM1-225/3p-200A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/160A' },
                    { power: 37, model: 'XJ01-37K/D220', plastic_case: 'CM1-225/3p-225A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/200A' },
                    { power: 45, model: 'XJ01-45K/D220', plastic_case: 'CM1-400/3p-250A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/250A' },
                ],
                "BP": [
                    { power: 0.75, model: 'XJ01-0.75S/D220', plastic_case: 'DZ47-3P-6A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/4A' },
                    { power: 1.1, model: 'XJ01-1.1S/D220', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/6A' },
                    { power: 1.5, model: 'XJ01-1.5S/D220', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-1210', thermal_relay: 'JR36-20/8A' },
                    { power: 2.2, model: 'XJ01-2.2S/D220', plastic_case: 'DZ47-3P-16A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/13A' },
                    { power: 3, model: 'XJ01-3S/D220', plastic_case: 'DZ47-3P-20A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/18A' },
                    { power: 4, model: 'XJ01-4S/D220', plastic_case: 'DZ47-3P-32A', contactor: 'CJX2-2510', thermal_relay: 'JR36-20/25A' },
                    { power: 5.5, model: 'XJ01-5.5S/D220', plastic_case: 'DZ47-3P-40A', contactor: 'CJX2-3210', thermal_relay: 'JR36-20/32A' },
                    { power: 7.5, model: 'XJ01-7.5S/D220', plastic_case: 'DZ47-3P-50A', contactor: 'CJX2-4011', thermal_relay: 'JR36-63/40A' },
                    { power: 11, model: 'XJ01-11S/D220', plastic_case: 'CM1-100/3p-80A', contactor: 'CJX2-6511', thermal_relay: 'JR36-63/63A' },
                    { power: 15, model: 'XJ01-15S/D220', plastic_case: 'CM1-100/3p-100A', contactor: 'CJX2-8011', thermal_relay: 'JR36-160/80A' },
                    { power: 18.5, model: 'XJ01-18.5S/D220', plastic_case: 'CM1-225/3p-125A', contactor: 'CJX2-9511', thermal_relay: 'JR36-160/100A' },
                    { power: 22, model: 'XJ01-22S/D220', plastic_case: 'CM1-225/3p-160A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/120A' },
                    { power: 30, model: 'XJ01-30S/D220', plastic_case: 'CM1-225/3p-200A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/160A' },
                    { power: 37, model: 'XJ01-37S/D220', plastic_case: 'CM1-225/3p-225A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/200A' },
                    { power: 45, model: 'XJ01-45S/D220', plastic_case: 'CM1-400/3p-250A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/250A' },
                ],
                "C": [
                    { power: 0.75, model: 'XJ01-0.75P/D220', plastic_case: 'DZ47-3P-6A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/4A' },
                    { power: 1.1, model: 'XJ01-1.1P/D220', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-0910', thermal_relay: 'JR36-20/6A' },
                    { power: 1.5, model: 'XJ01-1.5P/D220', plastic_case: 'DZ47-3P-10A', contactor: 'CJX2-1210', thermal_relay: 'JR36-20/8A' },
                    { power: 2.2, model: 'XJ01-2.2P/D220', plastic_case: 'DZ47-3P-16A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/13A' },
                    { power: 3, model: 'XJ01-3P/D220', plastic_case: 'DZ47-3P-20A', contactor: 'CJX2-1810', thermal_relay: 'JR36-20/18A' },
                    { power: 4, model: 'XJ01-4P/D220', plastic_case: 'DZ47-3P-32A', contactor: 'CJX2-2510', thermal_relay: 'JR36-20/25A' },
                    { power: 5.5, model: 'XJ01-5.5P/D220', plastic_case: 'DZ47-3P-40A', contactor: 'CJX2-3210', thermal_relay: 'JR36-20/32A' },
                    { power: 7.5, model: 'XJ01-7.5P/D220', plastic_case: 'DZ47-3P-50A', contactor: 'CJX2-4011', thermal_relay: 'JR36-63/40A' },
                    { power: 11, model: 'XJ01-11P/D220', plastic_case: 'CM1-100/3p-80A', contactor: 'CJX2-6511', thermal_relay: 'JR36-63/63A' },
                    { power: 15, model: 'XJ01-15P/D220', plastic_case: 'CM1-100/3p-100A', contactor: 'CJX2-8011', thermal_relay: 'JR36-160/80A' },
                    { power: 18.5, model: 'XJ01-18.5P/D220', plastic_case: 'CM1-225/3p-125A', contactor: 'CJX2-9511', thermal_relay: 'JR36-160/100A' },
                    { power: 22, model: 'XJ01-22P/D220', plastic_case: 'CM1-225/3p-160A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/120A' },
                    { power: 30, model: 'XJ01-30P/D220', plastic_case: 'CM1-225/3p-200A', contactor: 'CJ20-160', thermal_relay: 'JR36-160/160A' },
                    { power: 37, model: 'XJ01-37P/D220', plastic_case: 'CM1-225/3p-225A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/200A' },
                    { power: 45, model: 'XJ01-45P/D220', plastic_case: 'CM1-400/3p-250A', contactor: 'CJ20-250', thermal_relay: 'JR36-250/250A' },
                ]
            }
        };

        const circuitsContainer = document.getElementById('circuits-container');
        const addCircuitBtn = document.getElementById('add-circuit-btn');
        const resultContainer = document.getElementById('result-container');
        const circuitTemplate = document.getElementById('circuit-template');

        function updateAllResults() {
            const circuitCards = circuitsContainer.querySelectorAll('.circuit-card');
            if (circuitCards.length === 0) {
                resultContainer.innerHTML = '<p class="placeholder-text">请添加并配置回路以查看结果</p>';
                return;
            }

            let tableHtml = `
                <h2>选型汇总</h2>
                <table class="result-table">
                    <thead>
                        <tr>
                            <th>回路</th>
                            <th>电压</th>
                            <th>控制</th>
                            <th>功率 (kW)</th>
                            <th>型号</th>
                            <th>塑壳</th>
                            <th>接触器</th>
                            <th>热继</th>
                        </tr>
                    </thead>
                    <tbody>
            `;

            circuitCards.forEach((card, index) => {
                const voltageSelect = card.querySelector('.voltage');
                const controlMethodSelect = card.querySelector('.control-method');
                const motorPowerSelect = card.querySelector('.motor-power');

                const voltage = voltageSelect.value;
                const controlMethod = controlMethodSelect.value;
                const motorPower = parseFloat(motorPowerSelect.value);
                
                const selectedVoltageText = voltageSelect.options[voltageSelect.selectedIndex].text.split(', ')[1];
                const selectedControlMethodText = controlMethodSelect.options[controlMethodSelect.selectedIndex].text;
                const selectedMotorPowerText = motorPowerSelect.options[motorPowerSelect.selectedIndex].text;

                const dataGroup = selectionData[voltage] && selectionData[voltage][controlMethod];
                let resultRow = '';
                
                if (dataGroup) {
                    const result = dataGroup.find(item => item.power === motorPower);
                    if (result) {
                        resultRow = `
                            <td>${result.model}</td>
                            <td>${result.plastic_case}</td>
                            <td>${result.contactor}</td>
                            <td>${result.thermal_relay}</td>
                        `;
                    }
                }
                
                if (!resultRow) {
                    resultRow = `<td colspan="4" style="color: red;">未找到匹配型号</td>`;
                }

                tableHtml += `
                    <tr>
                        <td>${index + 1}</td>
                        <td>${selectedVoltageText}</td>
                        <td>${selectedControlMethodText}</td>
                        <td>${selectedMotorPowerText}</td>
                        ${resultRow}
                    </tr>
                `;
            });

            tableHtml += '</tbody></table>';
            resultContainer.innerHTML = tableHtml;
        }

        function updatePowerOptions(card) {
            const voltageSelect = card.querySelector('.voltage');
            const powerSelect = card.querySelector('.motor-power');
            
            const maxPower = (voltageSelect.value === 'D220') ? 45 : 280;

            for (const option of powerSelect.options) {
                const optionValue = parseFloat(option.value);
                option.style.display = (optionValue > maxPower) ? 'none' : '';
                option.disabled = (optionValue > maxPower);
            }

            if (powerSelect.options[powerSelect.selectedIndex].disabled) {
                for (const option of powerSelect.options) {
                    if (!option.disabled) {
                        powerSelect.value = option.value;
                        break;
                    }
                }
            }
        }

        function addCircuit() {
            const currentCircuits = circuitsContainer.querySelectorAll('.circuit-card').length;
            if (currentCircuits >= 4) return;

            const templateContent = circuitTemplate.content.cloneNode(true);
            const newCard = templateContent.querySelector('.circuit-card');
            
            circuitsContainer.appendChild(newCard);
            
            newCard.querySelector('.remove-btn').addEventListener('click', () => {
                newCard.remove();
                updateTitles();
                updateAllResults();
            });

            newCard.querySelectorAll('select').forEach(select => {
                select.addEventListener('change', () => {
                    if (select.classList.contains('voltage')) {
                        updatePowerOptions(newCard);
                    }
                    updateAllResults();
                });
            });
            
            updateTitles();
            updatePowerOptions(newCard);
            updateAllResults();
        }
        
        function updateTitles() {
            const circuitCards = circuitsContainer.querySelectorAll('.circuit-card');
            circuitCards.forEach((card, index) => {
                card.querySelector('.circuit-title').textContent = `回路 ${index + 1}`;
            });
            addCircuitBtn.disabled = circuitCards.length >= 4;
        }

        addCircuitBtn.addEventListener('click', addCircuit);

        // Add one circuit by default
        addCircuit();
    </script>
</body>
</html>
